import request from "@/utils/request";
import type { attrModel, attrResponseDataType, categoryResponseData } from "./model";

enum API {
  //一级分类接口地址
  category1 = "/admin/product/getCategory1",
  //二级分类接口地址
  category2 = "/admin/product/getCategory2/",
  //三级分类接口地址
  category3 = "/admin/product/getCategory3/",
  //获取某一个三级分类下全部平台属性与属性值
  getAttrList = "/admin/product/attrInfoList/",
  //新增平台属性属性值的接口
  addOrupdateAttr="/admin/product/saveAttrInfo",
  //删除平台属性值的接口
  deleteAttr="/admin/product/deleteAttr/"
}

//获取一级分类
export const reqCategory1 = () => request.get(API.category1);

//获取二级分类
export const reqCategory2 = (category1Id: number | string) =>
  request.get<any, categoryResponseData>(API.category2 + category1Id);

//获取三级分类
export const reqCategory3 = (category2Id: number | string) =>
  request.get<any, categoryResponseData>(API.category3 + category2Id);

//获取某一个三级分类下全部平台属性与属性值接口函数
export const reqGetAttrList = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string
) => request.get<any,attrResponseDataType>(API.getAttrList+`${category1Id}/${category2Id}/${category3Id}`);

//新增平台属性或者修改已有的平台属性的接口
export const reqAddOrUpdateAttr = (data:attrModel) => request.post(API.addOrupdateAttr,data)

//删除某一个已有平台属性
export const reqRemoveAttr = (attrId:number)=>request.delete<any,any>(API.deleteAttr+attrId)